package org.flashIso.engine.core {
	import flash.events.EventDispatcher;
	import flash.utils.getQualifiedClassName;
	
	/**
	 * @author Marius Dorin Moraru
	 */
	[Event(name="change", type="flash.events.Event")]
	public class ValidateableObject extends EventDispatcher implements IValidateable {
		private var _invalidated : Boolean = false;
		private var _autoValidation : Boolean = true;
		private var _atomic : Boolean = false;
		
		public function validateNow() : void {
			_invalidated = false;
		}

		public function get invalidated() : Boolean {
			return _invalidated;
		}
		public function set invalidated(value : Boolean) : void {
			_invalidated = value;
		}
		
		public function get atomicValidation() : Boolean {
			return _atomic;
		}
		public function set atomicValidation(value : Boolean) : void {
			_atomic = value;
		}

		public function get autoValidation() : Boolean {
			return _autoValidation;
		}
		public function set autoValidation(value : Boolean) : void {
			_autoValidation = value;
		}
		
		public function triggerValidation(...parameters) : void {
			if (_autoValidation){
				ValidateQue.add(this);
			}
		}
		
		public function get className() : String{
			var name:String = getQualifiedClassName(this);
			var index:int = name.indexOf("::");
			if (index >= 0) {
				name = name.substr(index + 2);
			}
			return name;
		}
	}
}
